import { defineStore } from 'pinia'

export const usePermissionStore = defineStore('permission', {
  state: () => ({
    isMenuInitialized: false,
    activeTopMenu: '/',
    topMenus: [],
    activeSideMenu: '',
    sideMenus: [], // 侧边栏 (从二级开始)
  }),
  actions: {
    setMenuInitialized(r) {
      this.isMenuInitialized = r
    },
    getCurrentSideMenus(rootName) {
      if (!rootName)
        return this.sideMenus
      return this.sideMenus.filter(
        item => item.meta?.parentName === rootName,
      )
    },
  },
})
